<template>
	<view class="changePwd_two">
		<view class="tit">绑定新手机号码</view>
		<view class="psw">
			<view class="new_psw">
				<text>手机号</text>
				<input type="text" placeholder="请输入新的手机号" v-model="phoneNumber">
			</view>
			<!-- <view class="new_psw">
				<text>确认新密码</text>
			    <input type="text" placeholder="再次输入新密码">		
			</view> -->
		</view>
		<button style="background-color: #00B2CA; color: #FFFFFF;" type="default" @click="confirm()">确认</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phoneNumber: ''
			}
		},
		onLoad() {

		},
		methods: {
			//提示
			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			//提交
			confirm() {
				let that = this
				let userInfo = uni.getStorageSync('userInfo')
				let contactNumberReg = /^1[0-9]{10}$/
				let contactNumberCheck = RegExp(contactNumberReg).test(this.phoneNumber)
				if (this.phoneNumber == '' || !contactNumberCheck) {
					this.showToast('请输入手机号')
				} else {
					uni.request({
						url: this.$serverUrl + 'ftUsers/updatePhone',
						data: {
							"userId": userInfo.id,
							"phone": this.phoneNumber
						},
						method: 'POST',
						success: (res) => {
							if (res.data.success) {
								let userInfo = uni.getStorageSync('userInfo')
								userInfo.phoneNumber = this.phoneNumber
								uni.setStorageSync('userInfo', userInfo)
								that.showToast('修改成功')
							} else {
								that.showToast('修改失败')
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
	.changePwd_two {
		margin: 88upx 36upx;
	}

	.tit {
		font-weight: bold;
		letter-spacing: 3upx;
		color: #333333;
		font-size: 36upx;
	}

	.tip {
		color: #666666;
		font-size: 30upx;
		margin-top: 26upx;
		margin-bottom: 52upx;
	}

	.new_psw {
		height: 124upx;
		display: flex;
		align-items: center;
	}

	.new_psw text {
		width: 30%;
	}

	button {
		background-color: #00B2CA;
		color: #FFFFFF;
		margin-top: 88upx;
	}
</style>
